var p1=document.createElement('p');
document.body.appendChild(p1);
function fpsMeter(){
	let prevTime = Date.now(),frames = 0;
	requestAnimationFrame(function loop(){
	  const time = Date.now();
	  const memory = performance.memory;
	  frames++;
	  if (time > prevTime + 1000){
		let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
		prevTime = time;
		frames = 0;
		let mem='0M';
		if(memory){
			mem=(memory.usedJSHeapSize/(1024*1024)).toFixed(2)+'M';
		}
		p1.innerHTML=`FPS: ${fps}<br>MEM: ${mem}`;
		// if(callBack){
		// 	callBack({fps:fps,mem:mem});
		// }
		//console.info('FPS: ', fps);
		//console.log('JS heap size limit:', memory.jsHeapSizeLimit); //上下文内可用堆的最大体积，以字节计算。
		//console.log('JS heap used size:', memory.usedJSHeapSize);//当前 JS 堆活跃段（segment）的体积，以字节计算。
		//console.log('JS heap total size:', memory.totalJSHeapSize);//已分配的堆体积，以字节计算。
	  }
	  requestAnimationFrame(loop);
	});
  }
  fpsMeter();

  /***复制到浏览器中使用
  function fpsMeter(){
	let prevTime = Date.now(),frames = 0;
	requestAnimationFrame(function loop(){
	  const time = Date.now();
	  const memory = performance.memory;
	  frames++;
	  if (time > prevTime + 1000){
		let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
		prevTime = time;
		frames = 0;
        var mem=(memory.usedJSHeapSize/(1024*1024)).toFixed(2)+'M';
		console.info('FPS: ', fps,'mem:',mem);
	  }
	  requestAnimationFrame(loop);
	});
  }
  fpsMeter();
   */